package com.soufang.soufangdemo.base;

public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private int code = Status.INTERNAL_SERVER_ERROR.value();

    public BusinessException(Throwable t) {
        super(t);
        if (t instanceof BusinessException) {
            this.code = ((BusinessException) t).getCode();
        }
    }

    public BusinessException(String message, Throwable t) {
        super(message, t);
        if (t instanceof BusinessException) {
            this.code = ((BusinessException) t).getCode();
        }
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(Status status) {
        super(status.getReasonPhrase());
        this.code = status.value();
    }

    public BusinessException(Status status, Throwable t) {
        super(status.getReasonPhrase(), t);
        this.code = status.value();
    }

    public int getCode() {
        return code;
    }

}
